package ht.controller;

import ht.domain.*;
import ht.ser.IndexSer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import qt.domain.Role;
import qt.domain.User;
import qt.domain.UserShow;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by charmyyy on 2017/10/20.
 */
@Controller
@RequestMapping("/index")
public class IndexController {
    @Resource(name = "indexSerImpl")
    private IndexSer indexSer;

    @RequestMapping("/admin")
    public String admin() {
        return "ht/admin";
    }

    @RequestMapping("/lyxx")
    public String lyxx() {
        return "ht/jsps/lyxx";
    }

    @RequestMapping("/xzqhxx")
    public String xzqhxx() {
        return "ht/jsps/xzqhxx";
    }

    @RequestMapping("/sxxx")
    public String sxxx() {
        return "ht/jsps/sxxx";
    }

    @RequestMapping("/czdjxx")
    public String czdjxx() {
        return "ht/jsps/czdjxx";
    }

    @RequestMapping("/czlxxx")
    public String czlxxx() {
        return "ht/jsps/czlxxx";
    }

    @RequestMapping("/czflxx")
    public String czflxx() {
        return "ht/jsps/czflxx";
    }

    @RequestMapping("/ssxmxx")
    public String ssxmxx() {
        return "ht/jsps/ssxmxx";
    }


    @RequestMapping("/mlx")
    public String mlx() {
        return "ht/jsps/mlx";
    }

    @RequestMapping("/relation")
    public String relation() {
        return "ht/jsps/relation";
    }

    @RequestMapping("/formula")
    public String formula() {
        return "ht/jsps/formula";
    }


    @RequestMapping("/user")
    public String user() {
        return "ht/jsps/user";
    }

    @RequestMapping("/role")
    public String role() {
        return "ht/jsps/role";
    }

    /*
    ----------------------以下返回的是json字符串！-----------------------------
     */

    @ResponseBody
    @RequestMapping("/lymc/all")
    public Page<Lyxx> getPageLymc(String start, String limit) {
//        System.out.println(start);
//        System.out.println(limit);
        return indexSer.getPageLymc(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/lymc/add")
    public Response addLymc(Lyxx h) {
        if (indexSer.addLymc(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/lymc/uppt")
    public Response upptLymc(Lyxx h) {
        if (indexSer.upptLymc(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;

        }
    }

    @ResponseBody
    @RequestMapping("/lymc/dele")
    public Response deleLymc(String bscd) {
        if (indexSer.deleLymc(bscd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/xzqhxx/all")
    public Page<XzqhxxShow> getPageXzqhxx(String start, String limit) {
//        System.out.println(start);
//        System.out.println(limit);
        return indexSer.getPageXzqhxx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/xzqhxx/add")
    public Response addXzqhxx(Xzqhxx h) {
        if (indexSer.addXzqhxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/xzqhxx/uppt")
    public Response upptXzqhxx(Xzqhxx h) {
        if (indexSer.upptXzqhxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/xzqhxx/dele")
    public Response deleXzqhxx(String addvcd) {
        if (indexSer.deleXzqhxx(addvcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/xzqhxx/combo")
    public List<Combo> comboXzqhxx() {
        List<Xzqhxx> list = indexSer.getAllXzqhxx();
        List<Combo> llist = new ArrayList<Combo>();
        for (Xzqhxx x : list) {
            Combo c = new Combo(x.getAddvnm(), x.getAddvcd());
            llist.add(c);
        }
        return llist;
    }

    @ResponseBody
    @RequestMapping("/czdjxx/all")
    public Page<Czdjxx> getPageCzdjxx(String start, String limit) {
//        System.out.println(start);
//        System.out.println(limit);
        return indexSer.getPageCzdjxx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/czdjxx/add")
    public Response addCzdjxx(Czdjxx h) {
        if (indexSer.addCzdjxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czdjxx/uppt")
    public Response upptCzdjxx(Czdjxx h) {
        if (indexSer.upptCzdjxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czdjxx/dele")
    public Response deleCzdjxx(String stgrdcd) {
        if (indexSer.deleCzdjxx(stgrdcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    //行政区划部分
    @RequestMapping("/hlxx")
    public String hlxx() {
        return "ht/jsps/hlxx";

    }

    @ResponseBody
    @RequestMapping("/hlxx/all")
    public Page<Hlxx> getPageHlxx(String start, String limit, String nm) {
        //System.out.println(start);
//        System.out.println(limit);
//        System.out.println(nm);
        if (nm == null || nm.equals("")) {
            return indexSer.getPageHlxx(Integer.parseInt(start), Integer.parseInt(limit));
        } else {
            return indexSer.getPageHlxxByNm(Integer.parseInt(start), Integer.parseInt(limit), nm);
        }

    }

    @ResponseBody
    @RequestMapping("/hlxx/add")
    public Response addHlxx(Hlxx h) {
        if (indexSer.addHlxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/hlxx/uppt")
    public Response upptHlxx(Hlxx h) {
        if (indexSer.upptHlxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/hlxx/dele")
    public Response deleHlxx(String rvcd) {
        if (indexSer.deleHlxx(rvcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    //

    //管理单位信息部分
    @RequestMapping("/gldw")
    public String gldw() {
        return "ht/jsps/gldw";

    }

    @ResponseBody
    @RequestMapping("/gldw/all")
    public Page<Gldw> getPageGldw(String start, String limit, String nm) {
        //System.out.println(start);
        //System.out.println(limit);
        //System.out.println(nm);
        if (nm == null || nm.equals("")) {
            return indexSer.getPageGldw(Integer.parseInt(start), Integer.parseInt(limit));
        } else {
            return indexSer.getPageGldwByNm(Integer.parseInt(start), Integer.parseInt(limit), nm);
        }

    }

    @ResponseBody
    @RequestMapping("/gldw/add")
    public Response addGldw(Gldw h) {
        if (indexSer.addGldw(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/gldw/uppt")
    public Response upptGldw(Gldw h) {
        if (indexSer.upptGldw(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/gldw/dele")
    public Response deleGldw(String admagcd) {
        if (indexSer.deleGldw(admagcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    //


    @ResponseBody
    @RequestMapping("/sxxx/all")
    public Page<Sxxx> getPageSxxx(String start, String limit) {
        //System.out.println(start);
        //System.out.println(limit);
        return indexSer.getPageSxxx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/sxxx/add")
    public Response addSxxx(Sxxx h) {
        if (indexSer.addSxxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/sxxx/uppt")
    public Response upptSxxx(Sxxx h) {
        if (indexSer.upptSxxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/sxxx/dele")
    public Response deleSxxx(String hncd) {
        if (indexSer.deleSxxx(hncd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czflxx/all")
    public Page<Czflxx> getPageCzflxx(String start, String limit) {
        //System.out.println(start);
        //System.out.println(limit);
        return indexSer.getPageCzflxx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/czflxx/add")
    public Response addCzflxx(Czflxx h) {
        if (indexSer.addCzflxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czflxx/uppt")
    public Response upptCzflxx(Czflxx h) {
        if (indexSer.upptCzflxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czflxx/dele")
    public Response deleCzflxx(String stclcd) {
        if (indexSer.deleCzflxx(stclcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czlxxx/all")
    public Page<Czlxxx> getPageCzlxxx(String start, String limit) {
        //System.out.println(start);
        //System.out.println(limit);
        return indexSer.getPageCzlxxx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/czlxxx/add")
    public Response addCzlxxx(Czlxxx h) {
        if (indexSer.addCzlxxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czlxxx/uppt")
    public Response upptCzlxxx(Czlxxx h) {
        if (indexSer.upptCzlxxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/czlxxx/dele")
    public Response deleCzlxxx(String sttpcd) {
        if (indexSer.deleCzlxxx(sttpcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/ssxmxx/all")
    public Page<Ssxmxx> getPageSsxmxx(String start, String limit) {
        //System.out.println(start);
        //System.out.println(limit);
        return indexSer.getPageSsxmxx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/ssxmxx/add")
    public Response addSsxmxx(Ssxmxx h) {
        if (indexSer.addSsxmxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/ssxmxx/uppt")
    public Response upptSsxmxx(Ssxmxx h) {
        if (indexSer.upptSsxmxx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/ssxmxx/dele")
    public Response deleSsxmxx(String obitcd) {
        if (indexSer.deleSsxmxx(obitcd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }


    @ResponseBody
    @RequestMapping("/mlx/all")
    public Page<Mlx> getPageMlx(String start, String limit) {
        return indexSer.getPageMlx(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/mlx/add")
    public Response addMlx(Mlx h) {
        if (indexSer.addMlx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/mlx/uppt")
    public Response upptMlx(Mlx h) {
        if (indexSer.upptMlx(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/mlx/dele")
    public Response deleMlx(String tycd) {
        if (indexSer.deleMlx(tycd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/user/all")
    public Page<UserShow> getPageUser(String start, String limit) {
        return indexSer.getPageUser(Integer.parseInt(start), Integer.parseInt(limit));
    }

//    @ResponseBody
//    @RequestMapping("/user/all")
//    public Page<User> getPageUser(String start, String limit) {
//        return indexSer.getPageUser(Integer.parseInt(start), Integer.parseInt(limit));
//    }

    @ResponseBody
    @RequestMapping("/user/add")
    public Response addUser(User user) {
        if (indexSer.addUser(user) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/user/uppt")
    public Response upptUser(User user) {
        if (indexSer.upptUser(user) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/user/dele")
    public Response deleUser(String ucode) {
        if (indexSer.deleUser(ucode) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/role/all")
    public Page<Role> getPageRole(String start, String limit) {
        return indexSer.getPageRole(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/role/add")
    public Response addRole(Role role) {
        if (indexSer.addRole(role) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/role/uppt")
    public Response upptRole(Role role) {
        if (indexSer.upptRole(role) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/role/dele")
    public Response deleRole(String rolecd) {
        if (indexSer.deleRole(rolecd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }
    @ResponseBody
    @RequestMapping("/relation/all")
    public Page<Relation> getPageRelation(String start, String limit) {
        return indexSer.getPageRelation(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/relation/add")
    public Response addRelation(Relation relation) {
        if (indexSer.addRelation(relation) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/relation/uppt")
    public Response upptRelation(Relation relation) {
        if (indexSer.upptRelation(relation) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/relation/dele")
    public Response deleRelation(String rela) {
        if (indexSer.deleRelation(rela) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }
    @ResponseBody
    @RequestMapping("/user/combo")
    public List<Combo> comboRole() {
        List<Role> list = indexSer.getAllRole();
        List<Combo> llist = new ArrayList<Combo>();
        for (Role x : list) {
            Combo c = new Combo(x.getRolenm(), x.getRolecd());
            llist.add(c);
        }
        return llist;
    }

    @ResponseBody
    @RequestMapping("/dataSource/combo")
    public List<Combo> comboSjyxx() {
        List<DataSource> list = indexSer.getAllDataSource();
        List<Combo> llist = new ArrayList<Combo>();
        for (DataSource x : list) {
            Combo c = new Combo(x.getData_source(), x.getData_source_id());
            llist.add(c);
        }
        return llist;
    }

    @ResponseBody
    @RequestMapping("/formula/all")
    public Page<FormulaShow> getPageFormula(String start, String limit) {
        return indexSer.getPageFormula(Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/formula/add")
    public Response addFormula(Formula h) {
        if (indexSer.addFormula(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/formula/uppt")
    public Response upptFormula(Formula h) {
        if (indexSer.upptFormula(h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/formula/dele")
    public Response deleFormula(int param_id) {
        if (indexSer.deleFormula(param_id) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }
    /*
    @ResponseBody
    @RequestMapping("/  /all")
    public Page<    > getPage  (String start, String limit) {
        System.out.println(start);
        System.out.println(limit);
        return indexSer.getPage  (Integer.parseInt(start), Integer.parseInt(limit));
    }

    @ResponseBody
    @RequestMapping("/  /add")
    public Response add  (     h) {
        if (indexSer.add  (h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/  /uppt")
    public Response uppt  (     h) {
        if (indexSer.uppt  (h) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    @ResponseBody
    @RequestMapping("/  /dele")
    public Response dele  (String bscd) {
        if (indexSer.dele  (bscd) == 1) {
            return Response.TRUE;
        } else {
            return Response.FAIL;
        }
    }

    */

}
